home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 4.9 KB | 219 lines | [TEXT/MPS ] |
- /*
- File: UFailure.h
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 11/2/94 TMH deal with qDebug conditional compile
- <2> 9/21/94 TMH Remove Assertion()
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
-
- To Do:
- */
-
- // UFailure.h
- // Copyright © 1984-1994 by Apple Computer Inc. All rights reserved.
-
- #ifndef __UFAILURE__
- #define __UFAILURE__
-
- #ifndef __SETJMP__
- #include <setjmp.h>
- #endif
-
- #ifndef __Debug__
- #include "Debug.h"
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifdef qMacApp
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #endif qMacApp
-
-
- //----------------------------------------------------------------------------------------
- // This macro can be called on any variable to keep it out of a register. It is
- // used specifically in exception handling. Kludge to be used till volatile or
- // C++ exception handling is implemented.
- //----------------------------------------------------------------------------------------
-
- #define VOLATILE(a) ((void) &a)
-
-
- //----------------------------------------------------------------------------------------
- // Max and min error number constants
- //----------------------------------------------------------------------------------------
-
- const short minErr = -32768;
- const short maxErr = 32767;
-
-
- //----------------------------------------------------------------------------------------
- // FailInfo
- //----------------------------------------------------------------------------------------
-
- class FailInfo
- {
- public:
- jmp_buf savedState;
- OSErr error;
- long message;
- FailInfo* nextInfo;
- #if qDebugFailures
- short installed;
- #endif
-
- public:
- FailInfo();
-
- #if qDebugFailures
- ~FailInfo();
- #endif
-
- inline void ReSignal();
-
- inline void Success();
-
- inline void Reset();
- };
-
- typedef struct FailInfo *FailInfoPtr;
-
-
- //----------------------------------------------------------------------------------------
- // Global macro definitions
- //----------------------------------------------------------------------------------------
-
- // The Try macro has taken the place of the FailInfo::Try method, for the
- // reason that the code has to _always_ be inline. The decision as to
- // whether or not code is inlined is implemented very differently for various
- // compilers, and can be affected by options such as symbolics generation and
- // level of optimization. Because this decision is so far out of our control,
- // the only real guarantee is to implement Try as a macro…
- //
- // The old way:
- //
- // FailInfo fi;
- // if (fi.Try())
- // {
- // …
- //
- // The new way:
- // FailInfo fi;
- // Try(fi)
- // {
- // …
- //
-
- #if qPowerPC && !defined(__MWERKS__)
- extern "C" {
- extern int MASetJmp(jmp_buf env);
- extern void MALongJmp(jmp_buf, int);
- }
- #define Try(f) \
- f.nextInfo = gTopHandler; \
- gTopHandler = &f; \
- if (MASetJmp(f.savedState) == 0)
- #else
- #define Try(f) \
- f.nextInfo = gTopHandler; \
- gTopHandler = &f; \
- if (setjmp(f.savedState) == 0)
- #endif
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations
- //----------------------------------------------------------------------------------------
-
- extern FailInfoPtr gTopHandler;
-
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
-
- inline long BuildMessage(short lowWord, short highWord)
- { return ((long)highWord << 16) | lowWord; }
-
- void Failure(OSErr error, long message);
-
- void FailMemError();
-
- void FailResError();
-
- void FailNewMessage(OSErr error, long oldMessage, long newMessage);
-
- void FailNIL(void* p);
-
- void FailNILResource(Handle r);
-
- void FailOSErr(OSErr error);
-
- Boolean HandlerExists(FailInfoPtr testFailInfoPtr);
-
- void Success(FailInfo& fi);
-
- //••void ProgramBreak(const CStr255& grievance);
-
- //••void ProgramReport(const CStr255& grievance, const Boolean breakInDebugger);
-
- //----------------------------------------------------------------------------------------
- // FailInfo inline method definitions
- //----------------------------------------------------------------------------------------
-
- inline FailInfo::FailInfo()
- {
- error = noErr;
- message = 0;
- nextInfo = NULL;
- #if qDebugFailures
- installed = false;
- #endif
- }
-
- #if qDebugFailures
- inline FailInfo::~FailInfo()
- {
- if (installed)
- ASSERTPRINT(false,("You forgot to call success for your failure handler"));
- }
- #endif
-
- inline void FailInfo::ReSignal() { ::Failure(error, message); }
-
- #if qDebugFailures
- inline void FailInfo::Success() { ::Success(*this); }
- #else
- inline void FailInfo::Success() { gTopHandler = nextInfo; }
- #endif
-
- inline void FailInfo::Reset()
- {
- error = noErr;
- message = 0;
- nextInfo = NULL;
- #if qDebugFailures
- installed = 0;
- #endif
- }
-
-
- #endif
-